<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>

</head>
<body>
<div th:fragment="manholeCoverAlarm">
    <div class="alarm-pop-div-style manholeCoverWarningContent">
        <div class="alarm-pop-header">
            <div class="header-notice-style coverNotice">报警信息 : <span></span> 条</div>
            <!-- <div class="close-btn"></div> -->

        
        </div>
        <div class="cover-alarm-pop-body alarm-pop-body-style">
            <div class="cover-alarm-pop-box">
                <!-- TODO -->
            </div>
            <!-- 报警框侧边栏 -->
            <div class="alarm-list coverWarningInfo">
                <div class="top-arrow-btn nextPage"></div>
                <div class="list">
                    <!-- TODO -->
                </div>
                <div class="bottom-arrow-btn previousPage"></div>
            </div>
        </div>
    </div>
    <script type="text/javascript">

        //$(window).resize(function () {
            $(".manholeCoverWarningContent").css({
                position: "absolute",
                left: ($(window).width() - $(".manholeCoverWarningContent").outerWidth()) / 2,
                top: ($(window).height() - $(".manholeCoverWarningContent").outerHeight()) / 2
            });
        //});
        var coverMaxWarningSum;
        var coverMaxWarningNum = 0;
        
        var coverLiHeight = 198;
        var coverMoveNum;
        var coverMoveHeight;
        var coverPage = 0;
        var coverWarningIndex = 0;
        //实时添加
        function warningClear() {
            $(".cover-alarm-pop-body .cover-alarm-pop-box").html("");
        }
        for (var i = 1; i <= coverMaxWarningSum; i++) {
            (function (arg) {
                $(".coverWarningInfo .list-item span").text(i);
            })(i);
        }
        
        //井盖—— 页面初始化渲染未处理数据，报警弹出框/alarm/data/notdispose/welllid/byuser
        function manholeCoverWarningInit() {
            $.ajax({
                url: "/alarm/data/notdispose/welllid/byuser",
                type: "GET",
                async: false,
                success: function (result) {
                    if (result.status == "200") {
                    	coverMaxWarningSum = result.data.length;
                        
                        $(".coverNotice span").text(coverMaxWarningSum);
                      //设备切换按钮显示的数字
                      
                        $("#manholeCoverBtn .tip-alarm").text(coverMaxWarningSum);
                        for (var i = 0; i < result.data.length; i++) {
                            var data = result.data[i];
                            var address = data.device.address;
                            var linkMan1 = data.device.linkMain1 ? data.device.linkMain1 : "";
                            var linkMan2 = data.device.linkMain2 ? data.device.linkMain2 : "";
                            var linkMan3 = data.device.linkMain3 ? data.device.linkMain3 : "";
                            var linkMan4 = data.device.linkMain4 ? data.device.linkMain4 : "";
                            var linkPhone1 = data.device.linkPhone1 ? data.device.linkPhone1 : "";
                            var linkPhone2 = data.device.linkPhone2 ? data.device.linkPhone2 : "";
                            var linkPhone3 = data.device.linkPhone3 ? data.device.linkPhone3 : "";
                            var linkPhone4 = data.device.linkPhone4 ? data.device.linkPhone4 : "";
                            var devCode = data.device.devCode;
                            var deviceName = data.device.deviceName;
                            var time = data.beginTime;
                            var alarmId = data.alarmId;
                            coverSetAlertWarningInfo(deviceName, address, linkMan1, linkMan2, linkMan3, linkMan4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time);

                        }
                    } else {
                    	winTip.alert(result.message);
                    }
                }
            });
            //如果没有获取到数据，隐藏报警框
            if (!coverMaxWarningSum) {
                $(".manholeCoverWarningContent").hide();
                stopSound();
            } else {
                $(".manholeCoverWarningContent").show();
                coverAlertWarning();
            }
        };
        //井盖 —— 报警实时添加
        function manholeCoverWarningInitTime(deviceName, address, linkMan1, linkMan2, linkMan3, linkMan4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time) {

        	//console.log(deviceName, address, linkMain1, linkMain2, linkMain3, linkMain4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, returntime);
            coverMaxWarningSum++;
            $(".coverNotice span").text(coverMaxWarningSum);
            
            $("#manholeCoverBtn .tip-alarm").text(coverMaxWarningSum);
            
            coverAlertWarning();
            $(".manholeCoverWarningContent").show();
            coverSetAlertWarningInfo(deviceName, address, linkMan1, linkMan2, linkMan3, linkMan4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time);
        }

//        设置报警框内容
        function coverSetAlertWarningInfo(deviceName, address, linkman1, linkman2, linkman3, linkman4, linkPhone1, linkPhone2, linkPhone3, linkPhone4, devCode, alarmId, time) {
			coverMaxWarningNum++;
            //报警框右侧内容
            $(".coverWarningInfo .list").append('<div class="list-item"><span>' + coverMaxWarningNum + '</span>. 井盖异位</div>');
            //报警框左侧内容
            var dates = moment(time).format('YYYY-MM-DD');
            var seconds = moment(time).format('HH:mm:ss');
            $(".cover-alarm-pop-body .cover-alarm-pop-box").append('<div class="coverActiveContent active-content-style none">' +
                    '<div class="alarm-title">报警！！！</div>' +
                    '<div class="alarm-content-body">' +
                    '<div class="time-box">' +
                    '<div class="alarm-time">' +
                    '<div class="startTime">' + dates + '</div>' +
                    '<div class="w">WARNING</div>' +
                    '<div class="endTime">' + seconds + '</div>' +
                    '</div>' +
                    '</div>' +
                    '<div class="alarm-con">' +
                    '<div class="alarm-row">' +
                    '<label>地址：</label>' +
                    '<div class="alarm-address-box">' +
                    '<div class="con-right alarm-address">' + address + '</div>' +
                    '</div>' +
                    '</div>' +
                    '<div class="alarm-row ">' +
                    '<label>联系人：</label>' +
                    '<div class="con-right">' +
                    '<div>' +
                    '<span>' + linkman1 + ' </span>' +
                    '<span>' + linkPhone1 + '</span>' +
                    '<span>' + linkman2 + ' </span>' +
                    '<span>' + linkPhone2 + '</span>' +
                    '</div>' +
                    '<div>' +
                    '<span>' + linkman3 + ' </span>' +
                    '<span>' + linkPhone3 + '</span>' +
                    '<span>' + linkman4 + ' </span>' +
                    '<span>' + linkPhone4 + '</span>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '<div class="alarm-content-footer" devCode=' + devCode + ' alarmId=' + alarmId + '>' +
                    '<button class="warningHandle">处理</button>' +
                    '<button class="warningIgnore">忽略</button>' +
                    '</div>' +
                    '</div>' +

                    '</div>' +
                    '</div>');

            //页面初始化显示第一条信息
            $(".coverWarningInfo .list .list-item").eq(0).addClass("active").siblings().removeClass("active");
            $('.coverActiveContent').eq(0).removeClass('none').siblings().addClass("none");
        };
        //报警处理时，不同客户端同步处理
        function coverWarningSync(alarmId) {
            $(".alarm-content-footer").each(function () {
                if ($(this).attr("alarmId") == alarmId) {
                    $('.cover-alarm-pop-body .list-item').eq(coverWarningIndex).remove();
                    //右侧部分
                    $(".cover-alarm-pop-body .list-item").eq(coverWarningIndex).addClass('active').siblings().removeClass('active');
                    //左侧内容切换
                    $('.coverActiveContent').eq(coverWarningIndex).removeClass('none').siblings().addClass('none');

                    if (coverWarningIndex == coverMaxWarningSum - 1)
                    	coverWarningIndex--;
//                  右侧
                    $(".cover-alarm-pop-body .list-item").eq(coverWarningIndex).addClass('active').siblings().removeClass('active');
                    //左侧容切换
                    $("[alarmId=" + alarmId + "]").parents(".coverActiveContent").remove();
                    $('.coverActiveContent').eq(coverWarningIndex).removeClass('none').siblings().addClass('none');
                    //报警总数量更新
                    coverMaxWarningSum--;
                    coverMaxWarningNum--;
                    $(".coverNotice span").text(coverMaxWarningSum);
                    $("#manholeCoverBtn .tip-alarm").text(coverMaxWarningSum);
                    //当处理完成时按钮不在闪烁
                    /* if (coverMaxWarningSum > 0) {
                    	$('.manholeCoverHeader .historyBgc .historyMsg').attr("id", "coverTwinkle");
                    } else {
                        $('.manholeCoverHeader .historyBgc .historyMsg').removeAttr("id", "coverTwinkle");
                    } */
                    if (coverMaxWarningSum <= 0) {
                    	//关闭火警报警框
                        $(".manholeCoverWarningContent").hide();
                        stopSound();
                    }
                    coverWarningNum();
                }
            })
        }

        function coverAlertWarning() {

            $(".manholeCoverWarningContent").css({
                position: "absolute",
                left: ($(window).width() - $(".manholeCoverWarningContent").outerWidth()) / 2,
                top: ($(window).height() - $(".manholeCoverWarningContent").outerHeight()) / 2
            });

            $(".manholeCoverWarningContent").show();
            //报警tab栏头部切换功能
            $('.cover-alarm-pop-body').on("click", ".coverWarningInfo .list .list-item", function () {
            	coverWarningIndex = $(this).index();
//                    右侧部分
                $(this).addClass('active').siblings().removeClass('active');
//                    左侧内容切换
                $('.coverActiveContent').eq(coverWarningIndex).removeClass('none').siblings().addClass('none');
                return false;
            });
            //处理状态：1->处理，2->忽略
            var disposeStatusUrl = null;
            //点击处理,删除内容和选择的按钮
            $(".cover-alarm-pop-body .cover-alarm-pop-box").off().on("click", ".alarm-content-footer .warningHandle", function () {
            	var $this = $(this);
            	disposeStatusUrl = 1;
            	handleAlarmFunc($this,disposeStatusUrl);
            });
            //点击忽略,删除内容和选择的按钮
            $(".cover-alarm-pop-body .cover-alarm-pop-box").on("click", ".alarm-content-footer .warningIgnore", function () {
            	var $this = $(this);
            	disposeStatusUrl = 2;
            	handleAlarmFunc($this,disposeStatusUrl);
            });
            //处理和忽略的公共逻辑部分 
            function handleAlarmFunc($this,disposeStatusUrl) {
                var alarmId = $this.parent().attr("alarmId");
                var devCode = $this.parent().attr("devCode");
                $this.parents(".coverActiveContent").remove();
                $('.cover-alarm-pop-body .list-item').eq(coverWarningIndex).remove();
                $.ajax({
                    url: "/alarm/data/disposealarm",
                    type: "POST",
                    data: "devCode="+devCode+"&alarmId=" + alarmId + "&disposeStatus=" +disposeStatusUrl,
                    success: function (result) {
                        if (result.status == "200") {
                            if (coverWarningIndex == coverMaxWarningSum - 1)
                            	coverWarningIndex--;
//                          右侧
                            $(".cover-alarm-pop-body .list-item").eq(coverWarningIndex).addClass('active').siblings().removeClass('active');
//                          左侧容切换
                            $('.coverActiveContent').eq(coverWarningIndex).removeClass('none').siblings().addClass('none');
                            //报警总数量更新
                            coverMaxWarningSum--;
                            coverMaxWarningNum--;
                            $(".coverNotice span").text(coverMaxWarningSum);
                            $("#manholeCoverBtn .tip-alarm").text(coverMaxWarningSum);
                            //当处理完成时按钮不在闪烁
                            /* if (coverMaxWarningSum > 0) {
                            	$('.manholeCoverHeader .historyBgc .historyMsg').attr("id", "coverTwinkle");
                            } else {
                                $('.manholeCoverHeader .historyBgc .historyMsg').removeAttr("id", "coverTwinkle");
                            } */
							//如果设备切换按钮有数字则显示，否则隐藏
                            if (coverMaxWarningSum <= 0) {
                                $(".manholeCoverWarningContent").hide();
                                $("#manholeCoverBtn .tip-alarm").hide();
                                stopSound();
                            }
                            //如果是最后一页，处理完当前页数报警后翻到上一页
                            if (!(coverMaxWarningNum % 6)) {
                            	coverPage--;
                                if (coverPage <= 0) {
                                	coverPage = 0;
                                }
                                coverMoveNum = parseInt(coverMaxWarningSum / 6);
                                if (coverPage <= coverMoveNum && coverPage >= 0) {
                                	coverMoveHeight = coverLiHeight * coverPage;
                                    $(".cover-alarm-pop-body .list-item").eq(0).animate({marginTop: -coverMoveHeight + "px"}, 0);
                                }
                            }
                        } else {
                        	winTip.alert(result.message);
                        }
                    }
                });
                coverWarningNum();
            }

            //翻页

            //页数初始化
            //$(".previousPage").text(page+1);
            $(".cover-alarm-pop-body").on("click", ".previousPage", function () {
                //点击按钮下一页
                coverPage++;
                coverMoveNum = parseInt(coverMaxWarningSum / 6);
                if (coverPage >coverMaxWarningSum / 6) {
                	coverPage = coverMoveNum;
                }else if(coverPage == (coverMaxWarningSum / 6)){
                	coverPage = coverMoveNum-1;
                }
                if (coverPage <= coverMoveNum && coverPage >= 0) {
                	coverMoveHeight = coverLiHeight * coverPage;
                    $(".cover-alarm-pop-body .list-item").eq(0).animate({marginTop: -coverMoveHeight + "px"}, 0);
                }
            });
            $(".cover-alarm-pop-body").on("click", ".nextPage", function () {
                //点击按钮上一页
                coverPage--;
                if (coverPage <= 0) {
                	coverPage = 0;
                }
                coverMoveNum = parseInt(coverMaxWarningSum / 6);
                if (coverPage <= coverMoveNum && coverPage >= 0) {
                	coverMoveHeight = coverLiHeight * coverPage;
                    $(".cover-alarm-pop-body .list-item").eq(0).animate({marginTop: -coverMoveHeight + "px"}, 0);
                }else if(coverPage == (coverMaxWarningSum / 6)){
                	coverPage = coverMoveNum-1;
                }
                //$(".previousPage").text(page+1);
            });
        }
        //报警框右侧报警栏序号处理
/*         function coverWarningNum() {
            for (var i = 1; i <= coverMaxWarningSum; i++) {
                (function () {
                    $(".coverWarningInfo .list .list-item span").each(function (index, item) {
                        $(this).text(index + 1);
                    });
                })(i);
            }
        } */
        //改版，速度快 
        function coverWarningNum() {
            for (var i = 1; i <= coverMaxWarningSum; i++) {
                $(".coverWarningInfo .list-item").eq(i-1).find("span").text(i);
            }
        }

    </script>


</div>
</body>
</html>
